/**
 * 
 */
package com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.usersaction;

import com.alstudio.module.xmpp.protocol.xmpp.packact.ALXmppDomainConfig;
import com.alstudio.module.xmpp.protocol.xmpp.packact.IQNameSpace;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.AlXmlTag;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate;
import com.alstudio.module.xmpp.request.ALUiXmppRequestData;
import com.alstudio.utils.log.ALLog;

/**
 * @author alonso lee
 * 
 */
public class GetFriendIQCreator extends BaseIQTemplate {

	private final String start, end;
	private ALUiXmppRequestData data;
	
	/**
	 * 
	 */
	public GetFriendIQCreator(ALUiXmppRequestData data,String domain) {
		// TODO Auto-generated constructor stub
		this.data = data;

		start = data.getStartIndex();
		end = data.getEndIndex();
		this.domain = domain;
	
	}

	/**
	 * 
	 */
	public GetFriendIQCreator(String start, String end, String domain) {
		// TODO Auto-generated constructor stub
		this.start = start;
		this.end = end;
		this.domain = domain;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate
	 * #getIQXml()
	 */
	@Override
	public String getIQXml() {
		// TODO Auto-generated method stub
		AlXmlTag tag = new AlXmlTag("index");
		tag.setAtt("start", start);
		tag.setAtt("end", end);
		tagList.add(tag);
		if(data.getIntData() == 1){
			ALLog.d("获取粉丝列表");
			mALIQCreator.setNs(IQNameSpace.NS_FANS_LIST);
		}else{
			ALLog.d("获取好友列表");
			mALIQCreator.setNs(IQNameSpace.NS_FAVORITES_LIST);
		}
		mALIQCreator.setType(IQ_TYPE_GET);
		to = ALXmppDomainConfig.getALXmppDomainConfig().getDomainByNameSpace(mALIQCreator.getNs());
		mALIQCreator.setTo(to + domain);

		mALIQCreator.setTagList(tagList);
		String xml = "";
		try {
			xml = mALIQCreator.getXml();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return xml;
	}

}
